<?php
include  '../loginCheck.php';
include  '../Util.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>News</title>
        <link rel="stylesheet" type="text/css" href="view.css" media="all"/>
        <script type="text/javascript" src="view.js"></script>
        <script type="text/javascript" src="calendar.js"></script>
    </head>
    <body id="main_body" >

        <img id="top" src="top.png" alt=""/>
        <div id="form_container">

            <h1>
                <?php
                include  'menu.php';
                ?>
            </h1>
            <form id="form_144190" class="appnitro"  method="post" action="../adminResolveNews.php">
                <?php

                $link = Util::getLink();

                if (isset($_GET["textId"])) {
                    $query = sprintf(Util::$select_jornakDestinationAllByTextId,
                        mysql_real_escape_string($_GET["textId"])
                    );

                    $result = mysql_query($query);

                    if (!$result) {
                        die('Could not query:' . mysql_error() . '<br>' . $query);
                    }

                    $row = mysql_fetch_assoc($result);
                    $dateTime= $row['time'];

                    $query = sprintf(Util::$select_jornakText,
                        mysql_real_escape_string($_GET["textId"])
                    );
                    $result = mysql_query($query);

                    if (!$result) {
                        die('Could not query:' . mysql_error() . '<br>' . $query);
                    }
                    $row = mysql_fetch_assoc($result);
                }

                ?>
                <div class="form_description">
                    <h2>News | <a href ="newsEdit.php">Edit News</a> | <a href ="newsDelete.php">Delete News</a></h2>
                    <p>You are making new news.</p>
                </div>
                <ul >

                    <li id="li_1" >
                        <label class="description" for="element_1">News Header </label>
                        <div>
                            <input id="element_1" name="header" class="element text medium" type="text" maxlength="255" value="<?php echo stripslashes($row['header']) ?>"/>
                        </div><p class="guidelines" id="guide_1"><small>Headline.</small></p>
                    </li>		<li id="li_2" >
                        <label class="description" for="element_2">News Date </label>
                        <span>
                            <input id="element_2_1" name="dateM" class="element text" size="2" maxlength="2" value="<?php echo Util::getMonthFromDBDateTime($dateTime); ?>" type="text"/> /
                            <label for="element_2_1">MM</label>
                        </span>
                        <span>
                            <input id="element_2_2" name="dateD" class="element text" size="2" maxlength="2" value="<?php echo Util::getDayFromDBDateTime($dateTime); ?>" type="text"/> /
                            <label for="element_2_2">DD</label>
                        </span>
                        <span>
                            <input id="element_2_3" name="dateY" class="element text" size="4" maxlength="4" value="<?php echo Util::getYearFromDBDateTime($dateTime); ?>" type="text"/>
                            <label for="element_2_3">YYYY</label>
                        </span>

                        <span id="calendar_2">
                            <img id="cal_img_2" class="datepicker" src="calendar.gif" alt="Pick a date."/>
                        </span>
                        <script type="text/javascript">
                            Calendar.setup({
                                inputField	 : "element_2_3",
                                baseField    : "element_2",
                                displayArea  : "calendar_2",
                                button		 : "cal_img_2",
                                ifFormat	 : "%B %e, %Y",
                                onSelect	 : selectDate
                            });
                        </script>
                        <p class="guidelines" id="guide_2"><small>Date which will be shown.</small></p>
                    </li>		<li id="li_3" >
                        <label class="description" for="element_3">Text of the news </label>
                        <div>
                            <textarea id="element_3" name="text" class="element textarea large"><?php echo stripslashes($row['text']) ?></textarea>
                        </div><p class="guidelines" id="guide_3"><small>Body of your news.</small></p>
                    </li>
                     <li id="li_4" >
                        <label class="description" for="element_4">RSS description </label>
                        <div>
                            <input id="element_4" type="text" maxlength="255" size="50" name="rssDesc" class="element textarea large" value="<?php echo $row['present'] ?>"/>
                        </div><p class="guidelines" id="guide_4"><small>RSS description.</small></p>
                    </li>

                    <li class="buttons">
                        <input type="hidden" name="form_id" value="144190" />
                        <?php if (isset($_GET["textId"])) { ?>
                        <input type="hidden" name="saveEdit" value="true" />
                        <input type="hidden" name="oldTextId" value="<?php echo $_GET["textId"] ?>" />
                        <?php }else { ?>
                        <input type="hidden" name="saveNew" value="true" />
                        <?php } ?>
                        <input id="saveForm" class="button_text" type="submit" name="submit" value="Preview" />
                    </li>
                </ul>
                <input type="hidden" name="form_type" value="1" />
                <?php

                Util::closeLink($link);

                ?>
            </form>
            <div id="footer">

            </div>
        </div>
        <img id="bottom" src="bottom.png" alt=""/>
    </body>
</html>